# -*- coding:utf-8 -*-
"""
作者：xiaolu
日期：2022年09月28日
"""
from selenium import webdriver
import time
from selenium.webdriver.common.keys import Keys
import os
from selenium.webdriver.common.action_chains import ActionChains

# driver = webdriver.Chrome()

# 1.定位一组元素
# url = "file:///"+os.path.abspath("D:/pythontest/c2/checkbox.html")
# driver.get(url)
# time.sleep(3)
# driver.maximize_window()
# buttons = driver.find_elements_by_tag_name("input")
# for button in buttons:
#     if button.get_attribute('type') == 'checkbox':
#         button.click()
# time.sleep(3)
# driver.quit()

# 2.层级定位
# url = "file:///" + os.path.abspath("D:/pythontest/c2/level_locate.html")
# driver.get(url)
# driver.maximize_window()
# driver.find_element_by_partial_link_text("link1").click()
# action = driver.find_element_by_id("dropdown1").driver.find_element_by_partial_link_text("Another action")
# ActionChains(driver).move_to_element(action).perform()
# time.sleep(3)
# driver.quit()

# 3.下拉框定位
# url = "file:///"+os.path.abspath("D:/pythontest/c2/drop_down.html")
# driver.get(url)
# driver.maximize_window()
# xpath 定位
# driver.find_element_by_xpath("//*[@id="ShippingMethod"]/option[4]").click()
# 组定位
# options = driver.find_elements_by_tag_name("option")
# for option in options:
#     if option.get_attribute('value') == '9.03':
#         option.click()
# 数组下标定位
# options = driver.find_elements_by_tag_name("option")
# options[3].click()
# time.sleep(3)
# driver.quit()

# 4.alter框的处理
# url = "file:///"+os.path.abspath("D:/pythontest/c2/alert.html")
# driver.get(url)
# driver.set_window_size(600, 600)
# driver.find_element_by_partial_link_text("hover").click()
# time.sleep(3)
# # 获取alter框的操作句柄
# alter = driver.switch_to.alert
# time.sleep(3)
# # 关闭alter框
# alter.accept()
# time.sleep(3)
# driver.quit()

# 5.alter框中有输入框的处理
# url = "file:///"+os.path.abspath("D:/pythontest/c2/send.html")
# driver.get(url)
# driver.find_element_by_xpath("/html/body/input").click()
# time.sleep(3)
# alter = driver.switch_to.alert
# # alter框内输入文字
# alter.send_keys("小陆")
# time.sleep(2)
# alter.accept()
# time.sleep(3)
# driver.quit()

# 6.div对话框处理
# 适用于页面比较负载的情况,大大降低了元素因为重复属性无法唯一定位的问题
# url = "file:///"+os.path.abspath("D:/pythontest/c2/modal.html")
# driver.get(url)
# driver.find_element_by_link_text("Click").click()
# time.sleep(3)
# # 先定位元素所在的div
# div1 = driver.find_element_by_class_name("modal-body")
# # 在定位具体的元素
# div1.find_element_by_link_text("click me").click()
# time.sleep(3)
# div2 = driver.find_element_by_class_name("modal-footer")
# buttons = div2.find_elements_by_tag_name("button")
# buttons[0].click()
# time.sleep(3)
# driver.quit()

# 7.上传文件的操作
# url = "file:///"+os.path.abspath("D:/pythontest/c2/test7.html")
# driver.get(url)
# time.sleep(3)
# driver.find_element_by_name("file").send_keys("D:/pythontest/c2/1.png")
# time.sleep(3)
# driver.quit()
